//
//  HomeDataCenter.m
//  Safflower
//
//  Created by 袁亮 on 2016/11/28.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "HomeDataCenter.h"
#import "HomeMenuModel.h"

@implementation HomeDataCenter

-(void)fetchHomeMenuData:(void (^)(NSArray *))dataBlock
{
    NSArray *listData = @[@{@"menuImage":@"home_push_task_button",@"menuTitle":@"发布任务"},
                          @{@"menuImage":@"home_task_list_button",@"menuTitle":@"任务列表"},
                          @{@"menuImage":@"home_friend_list_button",@"menuTitle":@"好友列表"},
                          @{@"menuImage":@"home_setting_button",@"menuTitle":@"设置一下"}];
    
    NSArray *modelData = [NSArray yy_modelArrayWithClass:[HomeMenuModel class] json:listData];
    dataBlock(modelData);
}

- (void)fetchHomeCarouselData:(void (^)(NSArray *, NSString *))complation
{
    [HttpRequest POSTRequest:HomeCarousel WithParams:nil WithSuccess:^(id responseOjbect) {
        
        if ([[responseOjbect objectForKey:@"code"] integerValue] == 1) {
            NSArray *dataArray = (NSArray *)[responseOjbect objectForKey:@"data"];
            NSArray *modelData = [NSArray yy_modelArrayWithClass:[HomeCarouselModel class] json:dataArray];
            NSMutableArray *data = [NSMutableArray array];
            for (int i = 0; i < modelData.count; i ++) {
                HomeCarouselModel *model = [modelData objectAtIndex:i];
                [data addObject:[NSString stringWithFormat:@"%@%@",BaseIp,model.image]];
            }
            
            complation([data copy], nil);
            
        }else{
            complation(nil,[responseOjbect objectForKey:@"message"]);
        }
        
        
    } WithFail:^(NSError *error) {
        
        complation(nil,@"服务器异常");
        
    }];
}

@end
